package educationaladministrationsystem.CSM.Mapper.StudentAndTeacher.Teacher;

import educationaladministrationsystem.Class.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherCourseManagementMapper {
    @Select("select * from course where teacher=#{id} limit #{page},#{pageSum}")
    List<Course> getAllCourse(String id, int page, int pageSum);

    @Select("select name from teacher where id=#{id}")
    String getTeacherNameById(String id);

    @Select("select count(*) from course where id !=#{classId} and teacher=#{UID} and day=#{day} and (time between #{startTime} and #{endTime} or (time+constantTime)between #{startTime} and #{endTime})")
    int isTheSameTimeCourse(String UID, int day, int startTime, int endTime, String classId);

    @Select("select count(*) from course")
    int getCourseId();

    @Insert("insert into course values (#{id},#{name},#{credit},#{teacher},#{day},#{time},#{location},#{constantTime},#{instructionalMethod},#{degreeDemand},#{peopleNumber},#{peopleSum})")
    void addNewCourse(Course course);

    @Select("select * from course where id=#{id}")
    Course getCourseById(String id);

    @Update("update course set name=#{course.name},credit=#{course.credit},teacher=#{course.teacher},day=#{course.day},time=#{course.time},location=#{course.location},constantTime=#{course.constantTime},instructionalMethod=#{course.instructionalMethod},degreeDemand=#{course.degreeDemand},peopleNumber=#{course.peopleNumber},peopleSum=#{course.peopleSum} where id=#{oldId}")
    void updateCourse(Course course, String oldId);

    @Delete("delete from course where id=#{id}")
    void deleteCourse(String id);

    @Select("select count(*) from course where teacher=#{id}")
    int getCourseCount(String id);
}
